<?php

class Funcoes {

    private function cript($name) {
        $num = rand(0, 26);
        $name_cript = "";
        for ($letter = "a"; $letter != "aa"; $letter++) {
            $letra_normal[] = $letter;
            $letra_cript[$num++] = $letter;
            if ($num == 26)
                $num = 0;
        }

        for ($i = 0; $i < strlen($name); $i++) {
            $letra = substr($name, $i, 1);
            $pos_normal = array_search($letra, $letra_normal);
            if (is_int($pos_normal)) {
                $name_cript .= $letra_cript[$pos_normal];
            } else {
                $name_cript .= $letra;
            }
        }
        return $name_cript . $letra_normal[$num];
    }

    private function descript($name_cript) {
        $name = "";
        $check = substr($name_cript, strlen($name_cript) - 1, 1);
        for ($letter = "a"; $letter != "aa"; $letter++) {
            $letra_normal[] = $letter;
        }
        $check = array_search($check, $letra_normal);
        for ($i = 0; $i < strlen($name_cript) - 1; $i++) {
            $letra = substr($name_cript, $i, 1);
            $pos_cript = array_search($letra, $letra_normal);
            if (is_int($pos_cript)) {
                if ($pos_cript + $check > 26) {
                    $indice = $pos_cript + $check - 26;
                } else {
                    $indice = $pos_cript + $check;
                }
                $name .= $letra_normal[$indice];
            } else {
                $name .= $letra;
            }
        }
        return $name;
    }

}

?>
